#!/usr/bin/env python
# coding: utf-8

# In[5]:


import os
import sys
import requests
import matplotlib.pyplot as plt
from PIL import Image
from io import BytesIO

landmark_analyze_url = 'https://cvhzx.cognitiveservices.azure.com/' + "vision/v3.1/models/landmarks/analyze"
subscription_key='7388368827d942c5b517d8c6218ef191'
# Set image_url to the URL of an image that you want to analyze.
image_url = "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=748519320,4025628653&fm=26&gp=0.jpg"

headers = {'Ocp-Apim-Subscription-Key': subscription_key}
params = {'model': 'landmarks'}
data = {'url': image_url}
response = requests.post(
    landmark_analyze_url, headers=headers, params=params, json=data)
response.raise_for_status()

# The 'analysis' object contains various fields that describe the image. The
# most relevant landmark for the image is obtained from the 'result' property.
analysis = response.json()
assert analysis["result"]["landmarks"] is not []
print(analysis)
landmark_name = analysis["result"]["landmarks"][0]["name"].capitalize()

# Display the image and overlay it with the landmark name.
image = Image.open(BytesIO(requests.get(image_url).content))
plt.imshow(image)
plt.axis("off")
_ = plt.title(landmark_name, size="x-large", y=-0.1)
plt.show()


# In[ ]:





# ## 准备工作

# ### 地理编码

# In[6]:


#准备工作
import requests, json
import pandas as pd
from PIL import Image
from io import BytesIO
import geo
key='6f235d808725c41e91140d3d64b48632'


# In[7]:


def geocode(key,address,city=None,batch='false',sig=None,output='json',callback=None):
    url='https://restapi.amap.com/v3/geocode/geo?parameters'
    params={
    'key':key,
    'address':address,
    'city':city,
    'batch':batch,
    'sig':sig,
    'output':output,
    'callback':callback
    }
    response=requests.get(url,params=params)
    results=response.json()['geocodes'][0]['location']
    # return
    return results


# In[8]:


address1='广东省广州市中山大学南方学院'
中大南方_location=geocode(key,address1,city=None,batch='false',sig=None,output='json',callback=None)
中大南方_location


# ### 逆地理编码

# In[10]:


#准备工作
def regeo(key,location,poitype=None,radius='1000',extensions='base',batch='false',roadlevel=None,sig=None,
          output='json',callback=None,homeorcorp='0'):
    url='https://restapi.amap.com/v3/geocode/regeo?parameters'
    params={
        'key':key,
        'location':location,
        'poitype':poitype,
        'radius':radius,
        'extensions':extensions,
        'batch':batch,
        'sig':sig,
        'output':output,
        'callback':callback,
        'homeorcorp':homeorcorp
    }
    response=requests.get(url,params)
    results=response.json()
    return results


# In[11]:


location1="113.679287,23.632575"
geo.regeocode(key,location1,poitype=None,radius='1000',extensions='base',batch='false',roadlevel=None,sig=None,
          output='json',callback=None,homeorcorp='0')


# ## 路径规划

# ### 步行

# In[12]:


#步行
def walking(key,origin,location,sig=None,output='json',callback=None):
    url='https://restapi.amap.com/v3/direction/walking?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':location,
        'sig':sig,
        'output':output,
        'callback':callback,     
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results


# In[13]:


origin='113.678600,23.633329'
location='113.236244,23.128529'
geo.walking(key,origin,location,sig=None,output='json',callback=None)


# ### 公交

# In[14]:


#公交
def integrated(origin,location,city,cityid=None,extensions='base',strategy=0,nightflag=0,date=None,time=None,sig=None,output='json',callback=None):
    url='https://restapi.amap.com/v3/direction/transit/integrated?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':location,
        'city':city,
        'cityid':cityid,
        'extensions':extensions,
        'strategy':strategy,
        'nightflag':nightflag,
        'date':date,
        'time':time,
        'sig':sig,
        'output':output,
        'callback':callback
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results


# In[15]:


origin='113.678600,23.633329'
location='113.236244,23.128529'
city='广州'
strategy='1'
geo.integrated(key,origin,location,city,cityd=None,extensions='base',strategy=None,nightflag=0,date=None,time=None,sig=None)


# ## ip查询

# In[18]:


#IP定位
def ip(key,id):
    url='https://restapi.amap.com/v3/ip?parameters'
    key='18ef7dd6aeefc21dade574262c00f213'
    params={
        'key':key,
        'id':id
      
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results


# In[19]:


id='172.16.30.45'
ip(key,id)


# In[20]:


geo.ip(key,"172.16.30.45")


# ## 静态地图

# In[21]:


def amap(key,location,zoom,size='400*400',scale='1',markers=None,labels=None,paths=None,traffic='0',sig=None):
    url='https://restapi.amap.com/v3/staticmap?parameters'
    params={
    'key':key,
    'location':location,
    'zoom':zoom,
    'scale':scale,
    'markers':markers,
    'labels':labels,
    'paths':paths,
    'traffic':traffic,
    'sig':sig
    }
    r=requests.get(url,params)
    data=r.url
    return data


# In[22]:


location='114.398987,23.083845'
zoom='17'
amap(key,location,zoom,size='400*400',scale='1',markers=None,labels=None,paths=None,traffic=None,sig=None)


# In[23]:


geo.staticmap(key,"114.398987,23.083845")


# In[ ]:




